<template>
	<view>
		<view v-if="is_style=='button'" @click="on_login" class="flex j-c a-c b_y cff but_login">
			<text>微信授权登录</text>
		</view>
		<view v-if="is_style=='img'" @click="on_login">
			<image class="q_y login_icon" src="@/static/icon/weixin.png">
			</image>
		</view>
	</view>
</template>

<script>
	export default {
		name: "login-mp-weixin",
		props: {
			userName: {
				type: String,
				default: ''
			},
			avatarUrl: {
				type: String,
				default: ''
			},
			agr: {
				type: Boolean,
				default: false
			},
			agr: {
				type: Boolean,
				default: false
			},
			is_style: {
				type: String,
				default: 'button'
			},
		},
		data() {
			return {}
		},

		methods: {
			on_login(code) {
				if (!this.agr) {
					uni.showToast({
						title: '请勾选同意协议',
						icon: "none"
					});
					return;
				}
				let that = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						uni.showLoading({
							title: '正在登录中...'
						})
						that.mp_weixin_ajax(loginRes.code);
					}
				});
			},
			//微信小程序登录
			mp_weixin_ajax(code) {
				let that = this;
				let requestParams = {
					code: code,
					invite_code: uni.getStorageSync('invite_code'),
					avatarUrl: this.avatarUrl,
					userName: this.userName,
					iv: '',
					encryptedData: '',
				};
				this.Banmikeji.mp_wx_login(requestParams).then(ret => {
					if (ret != 0) {
						that.$emit('confirm', ret);
					}

				})
			},
		}
	}
</script>
<style lang="scss">
	.but_login {
		width: 600rpx;
		height: 80rpx;
		background-color: #1DC069;
	}
</style>